//
//  ViewController.m
//  UI07_UINavigationController
//
//  Created by LGC on 16/3/17.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "ViewController.h"
#import "VcOfSecond.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor orangeColor];
    [self configForNavigationItem];
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewWillAppear:(BOOL)animated {
    [self configForNavigationBar];
}
#pragma mark - 知识点1: UINavigationController
/** 
 * 导航控制器. 控制页面的跳转.
 * 需要指定一个根视图控制器.
 * 创建过程详见 AppDelegate.m 文件.
 * 在vc.m文件中, 通过vc.navigationController 找到离vc最近的navigationController 对象.
 */


#pragma mark - 知识点2: UINavigationItem

- (void)configForNavigationItem {
    
    // 中间(title)

    self.navigationItem.title = @"首页";
    
    // 左边(left)
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(handleCamere:)]autorelease];
    
    // 右边(rightBarButtonItem)
    UIBarButtonItem *r1 = [[UIBarButtonItem alloc]initWithTitle:@"next" style:UIBarButtonItemStylePlain target:self action:@selector(handleNext:)];
    UIBarButtonItem *r2 = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-tz.png"] style:UIBarButtonItemStylePlain target:self action:@selector(handleMap:)];
    
    self.navigationItem.rightBarButtonItems = @[r1, r2];
    
    [r1 release];
    [r2 release];
}

- (void)handleCamere:(UIBarButtonItem *)button {
    NSLog(@"dd");
}


- (void)handleMap:(UIBarButtonItem *)button {
    NSLog(@"救我");
}
#pragma mark - 知识点3: UINavigationBar

- (void)configForNavigationBar {
    
    // 隐藏(默认是NO).
    self.navigationController.navigationBarHidden = NO;
    
    // batTintColor
//    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
//    
    // tintColor
    self.navigationController.navigationBar.tintColor = [UIColor blueColor];
    
    // style
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    // 是否透明
    self.navigationController.navigationBar.translucent = YES;
    
}
#pragma mark - 知识点4: 通过NavigationController跳转界面.

/** 详见 handleNext: 方法. */
/** 跳转到下一页面 */
- (void)handleNext:(UIBarButtonItem *)button {
    
    // 创建下一页面对象.
    VcOfSecond *second = [[VcOfSecond alloc]init];
    
    // navigationController 推出新页面.
    [self.navigationController pushViewController:second animated:YES];
    
    [second release];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
